<?php
declare (strict_types = 1);
namespace app\course\model\base;

use app\common\model\BaseModel;
use app\user\model\user\Account;
use think\model\relation\BelongsTo;

/**
 * 证书模型
 */
class CourseCert extends BaseModel
{
    /**
     * 表名
     * @var string
     */
    protected $name = 'course_cert';

    /**
     * 设置自动写入时间
     *
     * @var boolean
     */
    protected $autoWriteTimestamp = true;

    /**
     * 不需要更新时间
     *
     * @var boolean
     */
    protected $updateTime = false;

    /**
     * 定义字段类型
     * @var array
     */
    protected $type = [
        'id'          => 'integer',
        'user_id'     => 'integer',
        'course_id'   => 'integer',
        'create_time' => 'integer',
    ];

    /**
     * 关联的用户名
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/12/21
     *
     * @return BelongsTo
     */
    public function userName(): BelongsTo
    {
        return $this->belongsTo(Account::class, 'user_id')->removeOption('soft_delete')->removeWhereField('mhm_id')->bind(['user_name']);
    }

    /**
     * 关联的用户昵称
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/12/21
     *
     * @return BelongsTo
     */
    public function nickName(): BelongsTo
    {
        return $this->belongsTo(Account::class, 'user_id')->removeOption('soft_delete')->removeWhereField('mhm_id')->bind(['nick_name']);
    }

    /**
     * 关联课程
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/12/21
     *
     * @return BelongsTo
     */
    public function course(): BelongsTo
    {
        return $this->belongsTo(Course::class, 'course_id')->bind(['course_title' => 'title', 'course_type', 'mhm_id']);
    }


}
